/**
 * 视频设备videoDeviceList.js
 * 版本号： v1.0.0
 */
$(function () {
    /**
     *视频设备列表
     */
    var prId = $("#projectId_").val();
    var onLineStatus = $("#onlineStatus_").val();
    var lastChecked = null;
    $("#videoDevice_dataList").datagrid({
        fit: true,
        fitColumns: true,
        method: "POST",
        rownumbers: true,
        singleSelect: true,
        border: false,
        url: CONTEXT_PATH + '/videoDevData/videoDeviceList.do',
        queryParams: {prId:prId,onLineStatus:onLineStatus},
        idField: 'vpId',
        frozenColumns: [[
            {field: 'vpId', checkbox: true}
        ]],
        columns: [
            [
                {field: 'deviceId', title: '设备编号', width: 100, align: 'left',fixed:true},
                {field: 'vpName', title: '项目检测点名称', width: 150, align: 'left',fixed:true},
                {field: 'principal', title: '负责人', width: 70, align: 'left',fixed:true},
                {field: 'onLineStatus', title: '在线状态', width: 70, align: 'center',fixed:true,
                    formatter:function(val){
                        if (val == 1) return "<span style='color: green; font-weight: bold'>在线</span>";
                        if (val == 2) return "<span style='color: red; font-weight: bold'>离线</span>";
                    }
                },
                {field: 'onlineTime', title: '在线时间', width: 140, align: 'left'}
            ]
        ],
        onLoadSuccess: function (data) {
            if (data.rows.length > 0) {
                lastChecked = null;
                $("#videoDevice_dataList").datagrid("selectRow", 0);
            }
        },
        onCheck:function(rowIndex, rowData){
            var row = $("#videoDevice_dataList").datagrid("getChecked");
            if(row && rowIndex == lastChecked){
                $('#videoDevice_dataList').datagrid("unselectAll");//取消选中当前所有行
                lastChecked = null;
            }else{
                lastChecked = rowIndex;
            }
        }
    });
});

